#include <bits/stdc++.h>

using namespace std;

const int N = 100 + 10;

int a[N];
int dp[N][N][N];

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];

        if (n <= 15)
        {
            int ans = 0;
            for (int st = 0; st < (1<<n); st++)
            {
                int res = 0;
                for (int i = 1; i <= n; i++)
                    for (int j = i-1; j >= 1; j--)
                    {
                        if (((st>>(i-1))&1) ^ ((st>>(j-1))&1) == 0)
                        {
                            if (a[i] == a[j])
                                res += a[i];
                            break;
                        }
                    }
                ans = max(ans, res);
            }

            cout << ans << endl;
        }
        else
        {
            dp[1][1][0] = dp[1][0][1] = 0;
            for (int i = 1; i <= n; i++)
            {
                // blue
                int k = i-1;
                for (int j = 0; j < i-1; j++)
                    dp[i][j][i] = dp[i][j][k] + (a[i] == a[k] ? a[i] : 0);

                int j = i-1;
                for (int k = 0; k < i-1; k++)
                    dp[i][j][i] = dp[i][j][k] + (a[i] == a[k] ? a[i] : 0);

                // red
                j = i-1;
                for (int k = 0; k < i-1; k++)
                    dp[i][i][k] = dp[i][j][k] + (a[i] == a[j] ? a[i] : 0);

                k = i-1;
                for (int j = 0; j < i-1; j++)
                    dp[i][i][k] = dp[i][j][k] + (a[i] == a[j] ? a[i] : 0);
            }

            int ans = 0;
            for (int j = 0; j < n; j++)
                ans = max(ans, dp[n][j][n]);
            for (int k = 0; k < n; k++)
                ans = max(ans, dp[n][n][k]);
            cout << ans << endl;
        }
    }

    return 0;
}